
function [] = test_fir_min_phase()

fs = get_sampling_fq();

% min-phase

cvs = importdata('..\..\genblep\sinc-min-phase-a1200-pal.csv');

d5 = cvs(:, 1)';
d5 = d5 / trapz(d5);

d6 = firwin('a1200', fs, 21000, 2048, false);
d8 = fir_min_phase(d6);

figure(1);
hold on;
title('min phase');
plot(d8, '*');
plot(d5, 'm');
legend('my-sinc-my-min-blip', 'python-min-blip');

error_calc(d8, d5);

% fq

D8 = fftshift(abs(fft(d8)));
D5 = fftshift(abs(fft(d5)));
fx = linspace(-fs/2, fs/2, 2048);

figure(2);
hold on;
title('min phase fq');
plot(fx, D8, '.');
plot(fx, D5, 'r');
legend('my min', 'python min');

% my vs rceps

fs = 7093790/2;
d1 = firwin('a1200', fs, 21000, 2047);
d2 = fir_min_phase(d1);
[~, d3] = rceps(d1);

figure(3);
hold on;
plot(d1, 'r');
plot(d2, 'g');
plot(d3, 'b');
title('rceps in time');
legend('sinc', 'my-min', 'matlab');

D1 = abs(fftshift(fft(d1)));
D2 = abs(fftshift(fft(d2)));
D3 = abs(fftshift(fft(d3)));
fx = linspace(-fs/2, fs/2, 2047);

figure(4);
hold on;
plot(fx, D1, '*');
plot(fx, D2, 'g');
plot(fx, D3, 'o');
title('rceps in fq');
legend('sinc', 'my-min', 'matlab-rceps');

end
